package com.io.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.io.dto.BaseRes;
import com.io.exception.BaseExceptionProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * The class/interface
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
@RestControllerAdvice
public class GlobeExceptionAdvice {

    @Autowired
    private Environment environment;

    @Autowired
    private ObjectMapper objectMapper;

    @ExceptionHandler(value = Throwable.class)
    public BaseRes exception(Throwable e, HttpServletRequest request, HttpServletResponse response) throws Exception {
        return BaseExceptionProcess.process(e, environment, objectMapper, request, response);
    }
}
